home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / rexx / ElAssign.lha / ElAssign / ElAssign.REXX < prev   
OS/2 REXX Batch file  |  1997-08-26  |  5KB  |  206 lines

  1. /*    Script which removes all assigns from a directory and all its
  2.     subdirectories and files and optionally deletes the directory with its
  3.     contents. $VER: ElAssign.REXX V1.0 (21.08.97) © Andrija Antonijevic
  4.  
  5.     Written by Andrija Antonijevic <TheAntony@bigfoot.com>.
  6.  
  7.     Many thanks to Charles Patterson <midian@azstarnet.com> whose
  8.     DeAssign.dopus5 gave me the idea to write my own version.
  9.  
  10.     I made the following improvements:
  11.  
  12.     - You don't need DOpus5 since it works with everything including
  13.       DOpus4, DOpus5 and any other kind of filemanager program.
  14.  
  15.     - It will remove all assigns from a directory and all its subdirectories
  16.       and files unless NODEEP option is specified.
  17.  
  18.     - Deleting chosen directory with all its contents is just an
  19.       option here. You can specify DELETE for deleting the directory
  20.       with confirmation and KILL for deleting without confirmation.
  21.  
  22.     - You can give any kind of path to the directory/file: using
  23.       complete path, relative path or assign.
  24.  
  25. Requirements:
  26. ~~~~~~~~~~~~~
  27.  
  28.     - rexxsupport.library (reqired)
  29.  
  30.     - rexxreqtools.library - only if you specify DELETE option
  31.       (see below)
  32.  
  33.     - Filemanager like DOpus4 or 5 will make things easier (optional ;))
  34.  
  35. Command line:
  36. ~~~~~~~~~~~~~
  37.  
  38.     ElAssign.REXX NAME [DELETE | KILL] [NODEEP]
  39.  
  40.  
  41.     NAME is the name of the file/directory to remove the assigns from.
  42.     If NAME has spaces in it, it must be enclosed with double quotes.
  43.  
  44.     DELETE deletes the directory but only if you confirm whilst
  45.     KILL is a silent killer ;) Default is not to delete anything.
  46.     DELETE will override KILL if you "accidentaly" put them both
  47.     into the command line.
  48.  
  49.     NODEEP instructs the script only to remove assigns from the
  50.     argument you specified (file or directory) and not to go
  51.     deep in the jungles of the directory (you can't go into
  52.     the file, can you?).
  53.  
  54.  
  55. Usage:
  56. ~~~~~~
  57.  
  58. From Shell:
  59.  
  60.     [RX] FullPath:ToScript/ElAssign.REXX NAME [DELETE | KILL] [NODEEP]
  61.  
  62. DOpus4:
  63.  
  64. Configuration/Buttons:
  65.  
  66. +--------+
  67. |AmigaDOS| RX FullPath:ToScript/ElAssign.REXX "{f}" [DELETE | KILL] [NODEEP]
  68. +--------+
  69.  
  70.     You might want to select "Do all files".
  71.     You can also set up a hotkey for the button.
  72.  
  73. DOpus5:
  74.  
  75.     I don't have DOpus5 but it's fairly easy to set this script up
  76.     with it. Please consult your DOpus5 manual to see how to do it.
  77.     Looking at installation instructions for DOpus4 ({f} is file name
  78.     which should be enclosed with double quotes) might help.
  79.  
  80.     Oh, yes. "El" in ElAssign doesn't have anything to do with Spain.
  81.     It's short from Eliminate :)
  82.  
  83.     Finally, if you find any bugs or have some suggestions, please contact
  84.     me (Andrija Antonijevic <TheAntony@bigfoot.com>).
  85. */
  86.  
  87. QUOTE='22'x
  88. LF='0A'x
  89. TempAssign='T:AssignResult'
  90. TempWhich='T:WhichResult'
  91. TempCD='T:CDResult'
  92. Quest='Do you really wish to delete'
  93. DoDel=0
  94. Deep=1
  95.  
  96. OPTIONS RESULTS
  97.  
  98. IF ~SHOW('L', 'rexxsupport.library') THEN IF ~ADDLIB('rexxsupport.library', 0, -30, 0) THEN DO 
  99.     SAY "Couldn't open rexxsupport.library!"
  100.     EXIT(10)
  101. END
  102.  
  103. PARSE ARG '"' Path '"' Temp Temp1 Temp2
  104. IF Path='' & Temp='' & Temp1='' & Temp2='',
  105.     THEN PARSE ARG Path Temp Temp1 Temp2
  106.  
  107. IF ~(EXISTS(Path)) | Path='' THEN DO
  108.     SAY 'Invalid file/dir specified!'
  109.     EXIT
  110. END
  111.  
  112. StorPath=Path
  113.  
  114. IF (UPPER(Temp)='KILL' | UPPER(Temp1)='KILL' | UPPER(Temp2)='KILL'),
  115.     THEN DoDel=2
  116. IF (UPPER(Temp)='DELETE' | UPPER(Temp1)='DELETE' | UPPER(Temp2)='DELETE'),
  117.     THEN DoDel=1
  118. IF (UPPER(Temp)='NODEEP' | UPPER(Temp1)='NODEEP' | UPPER(Temp2)='NODEEP'),
  119.     THEN Deep=0
  120.  
  121. IF DoDel=1 THEN IF ~SHOW('L','rexxreqtools.library') THEN IF ~ADDLIB('rexxreqtools.library',0,-30,0) THEN DO
  122.     SAY "Couldn't open rexxreqtools.library!"
  123.     EXIT(10)
  124. END
  125.  
  126. ADDRESS COMMAND 'Which 'QUOTE||Path||QUOTE' >'TempWhich
  127. Suc=OPEN(FHWh, TempWhich, 'R')
  128. IF Suc~=1 THEN DO
  129.     SAY "Couldn't open temporary file!"
  130.     EXIT(10)
  131. END
  132. Path=READLN(FHWh)
  133. CLOSE(FHWh)
  134. ADDRESS COMMAND 'Delete 'TempWhich' QUIET'
  135.  
  136. IF Path='' THEN DO
  137.     OldDir=PRAGMA('D', StorPath)
  138.     ADDRESS COMMAND 'CD >'TempCD
  139.     Suc=OPEN(FHCD, TempCD, 'R')
  140.     IF Suc~=1 THEN DO
  141.         SAY "Couldn't open temporary file!"
  142.         EXIT(10)
  143.     END
  144.     Path=READLN(FHCD)
  145.     CLOSE(FHCD)
  146.     ADDRESS COMMAND 'Delete 'TempCD' QUIET'
  147.     PRAGMA('D', OldDir)
  148. END    
  149.  
  150. IF Path='' THEN DO
  151.     SAY 'No file/dir supplied!'
  152.     EXIT(10)
  153. END
  154.  
  155. Leny=LENGTH(Path)
  156.  
  157. Cntr=0
  158. ADDRESS COMMAND 'Assign DIRS >'TempAssign
  159. Suc=OPEN(FHAss, TempAssign, 'R')
  160.  
  161. IF Suc~=1 THEN DO
  162.     SAY "Couldn't open temporary file!"
  163.     EXIT(10)
  164. END
  165.  
  166. Curr=0
  167. Line=READLN(FHAss)
  168. Line=READLN(FHAss)
  169.  
  170. DO WHILE ~EOF(FHAss)
  171.     Line=READLN(FHAss)
  172.     Prev=Curr
  173.     Curr=Curr+1
  174.     PARSE VAR Line Assign.Curr Dir.Curr
  175.     Dir.Curr=STRIP(Dir.Curr)
  176.     IF Assign.Curr="+" THEN Assign.Curr=Assign.Prev
  177.  
  178.     IF (Dir.Curr=Path) | (Deep & ((LEFT(Dir.Curr, Leny)=Path & SUBSTR(Dir.Curr, Leny+1,1)='/'),
  179.        | (LEFT(Dir.Curr, Leny)=Path & SUBSTR(Dir.Curr, Leny+1,1)=':'))),
  180.        THEN DO
  181.         Cntr=Cntr+1
  182.         RemAssign.Cntr=Assign.Curr
  183.         RemName.Cntr=Dir.Curr
  184.     END
  185. END
  186.  
  187. CLOSE(FHAss)
  188. ADDRESS COMMAND 'Delete 'TempAssign' QUIET'
  189.  
  190. IF Cntr>0 THEN DO
  191.     DO I=1 to Cntr
  192.         ADDRESS COMMAND 'Assign 'RemAssign.I': 'QUOTE||RemName.I||QUOTE' REMOVE'
  193.     END
  194. END
  195.  
  196. IF DoDel=1 THEN DO
  197.     RES=rtEZRequest(Quest||LF||LF||Path, '_Delete|_Cancel', 'ElAssign', 'rt_reqpos=reqpos_centerscr rtez_flags=ezreqf_centertext')
  198.     IF RES=0 THEN DoDel=0
  199. END
  200.  
  201. IF DoDel~=0 THEN DO
  202.     ADDRESS COMMAND 'Delete 'QUOTE||Path||QUOTE' ALL FORCE QUIET'
  203. END
  204.  
  205. EXIT
  206.